//
// Created by vcq on 21/4/14.
//

#pragma once

#include "model/teachgoal.hpp"

static void GetTeachGoal(request &req, response &res) {
    basic_string_view<char> id = req.get_query_value("id");
    basic_string_view<char> _require_id = req.get_query_value("_require_id");
    basic_string_view<char> _syllabus_id = req.get_query_value("_syllabus_id");
    json item = MGetTeachGoal(id, _require_id, _syllabus_id);
    res.set_status_and_content(status_type::ok, item.dump(), req_content_type::json);
}

static void SaveTeachGoal(request &req, response &res) {
    if (!check_login(req, res)) {
        return;
    }
    struct teachgoal teachgoal1{};
    teachgoal1.id = atoi(req.get_query_value("id").data());
    teachgoal1.name = req.get_query_value("name");
    teachgoal1._syllabus_id = atoi(req.get_query_value("_syllabus_id").data());
    teachgoal1._require_id = atoi(req.get_query_value("_require_id").data());
    teachgoal1.per = atof(req.get_query_value("per").data());
    teachgoal1.note = req.get_query_value("note");
    MAddTeachGoal(teachgoal1);
    res.set_status_and_content(status_type::ok);
}


static void DeleteTeachGoal(request &req, response &res) {
    if (!check_login(req, res)) {
        return;
    }
    MDeleteTeachGoal(req.get_query_value("id"));
    res.set_status_and_content(status_type::ok);
}
